package org.shopen.puremvc.controller.statehandlers.view
{
	import flash.display.DisplayObject;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.shopen.puremvc.ApplicationConstants;
	import org.shopen.puremvc.view.ApplicationMediator;
	import org.shopen.puremvc.view.CreateWindowMediator;

	public class StateChangedViewCommand extends SimpleCommand
	{
		override public function execute(notification:INotification):void
		{
			try
			{
				// TODO: implement
				var newState : String = notification.getType();
				var body : Object = notification.getBody();
				
				//showing popups
				switch (newState)
				{
					case ApplicationConstants.STATE_CREATING_CLOSED:
					case ApplicationConstants.STATE_CREATING_NEW:
					case ApplicationConstants.STATE_CREATING_SAVED:
						/* var obj : Object = facade.retrieveMediator(ApplicationMediator.NAME).getViewComponent();
						facade.registerMediator(new CreateWindowMediator(obj));
						sendNotification(ApplicationConstants.SHOW_CREATING_WINDOW, body); */
						break;
					case ApplicationConstants.STATE_OPENING_CLOSED:
					case ApplicationConstants.STATE_OPENING_NEW:
					case ApplicationConstants.STATE_OPENING_SAVED:
						sendNotification(ApplicationConstants.SHOW_OPENING_WINDOW, body);
						break;
					case ApplicationConstants.STATE_SAVING_CHANGED:
					case ApplicationConstants.STATE_SAVING_NEW:
						sendNotification(ApplicationConstants.SHOW_SAVING_WINDOW, body);
						break;
					case ApplicationConstants.STATE_SAVING_CLOSING_CHANGED:
					case ApplicationConstants.STATE_SAVING_CREATING_CHANGED:
					case ApplicationConstants.STATE_SAVING_OPENING_CHANGED:
						sendNotification(ApplicationConstants.SHOW_SAVING_PROMPT, body);
						break;
				}
			}
			catch(error : Error)
			{
				sendNotification(ApplicationConstants.GENERAL_ERROR, error);
			}
		}
	}
}